package dao;

import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import entity.PsInspectiontaskDetail;

@Repository("inspTaskDetailDao")
public class InspTaskDetailDao<K, V> extends HibernateDaoSupport{
	
	public List<PsInspectiontaskDetail> selectAllLine(int page,int rows,DetachedCriteria searchDc){
		return (List<PsInspectiontaskDetail>)this.getHibernateTemplate().findByCriteria(searchDc, (page-1)*rows, rows);
	}
	
	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	public void changeBugLever(PsInspectiontaskDetail psInspTaskDetail)  throws Exception{
		PsInspectiontaskDetail p=this.getHibernateTemplate().get(PsInspectiontaskDetail.class, psInspTaskDetail.getId());
		p.setBuglevel(psInspTaskDetail.getBuglevel());	
	}
	public int count(DetachedCriteria searchDc){
		searchDc.setProjection(Projections.rowCount());
		List<Long> count=(List<Long>)this.getHibernateTemplate().findByCriteria(searchDc);
		return count.get(0).intValue();
	}
}
